package com.awn.weidian.demo.mapper;

import java.util.List;

import com.awn.weidian.demo.pojo.Student;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;

@Mapper
public interface IStudent {

    @Select("select * from student")
    public List<Student> showStudent();


   // @Select("select * from student where name like #{keyword} or class_name = #{keyword} or phone = #{keyword} or school like #{keyword}")
    @SelectProvider(type = StudentMapper.class, method = "findone")
    public List<Student> findone(String keyword);

    /**
     * @desc Mybatis 动态sql语句处理方式，这里采用编写Java类的方式，调用Mybatis Provider注解完成
     */
    class StudentMapper{

        /**
         * 处理接口中检索功能
         * @param keyword 输入框内容
         * @return
         */
        public String findone(String keyword) {
            String sql = "select * from student";
            if((keyword != null) || !(keyword.equals(""))){
                sql += " where name like CONCAT('%',#{keyword},'%') " +
                        "or class_name like CONCAT('%',#{keyword},'%') " +
                        "or phone = #{keyword} " +
                        "or school like CONCAT('%',#{keyword},'%')";
            }
            return sql;
        }
    }

}
